﻿using MetroFramework.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WebConfigManager.TabPageControls;

namespace WebConfigManager
{
    public partial class FormSetting : MetroForm
    {
        List<PageConfigBase> listPages = new List<PageConfigBase>();

        private PageConfigWebService pageWebService = null;

        private PageConfigClient pageClientConfig = null;

        private PageConfigHzService pageHzService = null;

        public FormSetting()
        {
            InitializeComponent();
            CreatPages();
        }

        private void CreatPages()
        {
            pageWebService = new PageConfigWebService();
            pageClientConfig = new PageConfigClient();
            pageHzService = new PageConfigHzService();
            listPages.Add(pageWebService);
            listPages.Add(pageClientConfig);
            listPages.Add(pageHzService);
        }

        private void InitCtrls()
        {
            foreach(PageConfigBase page in listPages)
            {
                page.LoadConfig();
                page.InitCtrls();
            }
        }

        private bool UpdateData()
        {
            foreach (PageConfigBase page in listPages)
            {
                if(!page.UpdateData())
                {
                    return false;
                }
            }
            return true;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if(UpdateData())
            {
                MessageBox.Show("设置保存成功!");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void FormSetting_Load(object sender, EventArgs e)
        {
            InitCtrls();
            tabPageClientOption.Controls.Add(pageClientConfig);
            tabPageWebOption.Controls.Add(pageWebService);
            tabPageHzWebOption.Controls.Add(pageHzService);
        }
    }
}
